# coding=utf-8
from time import sleep
from threading import Thread

"""
类包装创建线程
"""


class MyThread(Thread):
    def __init__(self, name):
        Thread.__init__(self)
        self.name = name

    # 重写run方法
    def run(self):
        print(f"线程{self.name}, start")  # format
        for i in range(3):
            print(f"线程：{self.name}, {i}")
            sleep(1)
        print(f"线程{self.name}, end")  # format


if __name__ == '__main__':
    print("主线程，start")
    # 创建线程(类的方式)
    t1 = MyThread("t1")
    # t1设置为守护线程
    t1.setDaemon(True)
    # 启动线程
    t1.start()
    print("主线程，end")
